#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repone(i, n) for (int i = 1; i <= n; ++i)
#define reprange(i,a,b) for(int i=(a);i<=(b);++i)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",&s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;
const int mod = 1000000007;
const int MOD = 998244353;
const char nline = '\n';
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.se); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*-------------------------------------------------------------------------------------------------------------------------------------------*/
void solve() {
int q;
cin >> q;
vector<int> v(2e5 + 5, 0);
int l = 0, r = 0;
for (int i = 0; i < q; i++) {
char c; cin >> c;
int id; cin >> id;
if (i == 0) {
v[id] = l;
l--;
r++;
continue;
}
if (c == 'L') {
v[id] = l;
l--;
}
else if (c == 'R') {
v[id] = r;
r++;
}
else {
cout << min(abs(v[id] - l), abs(v[id] - r)) - 1 << nline;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("Errorf.in", "w", stderr);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
for (ll i = 1; i <= t; i++) {
//cout << "Case " << i << ": " ;
solve();
}
return 0;
}
544B - Sea and Islands | 152B - Steps |
1174D - Ehab and the Expected XOR Problem | 1511A - Review Site |
1316A - Grade Allocation | 838A - Binary Blocks |
1515D - Phoenix and Socks | 1624D - Palindromes Coloring |
1552F - Telepanting | 1692G - 2Sort |
1191A - Tokitsukaze and Enhancement | 903A - Hungry Student Problem |
52B - Right Triangles | 1712A - Wonderful Permutation |
1712D - Empty Graph | 1712B - Woeful Permutation |
1712C - Sort Zero | 1028B - Unnatural Conditions |
735B - Urbanization | 746C - Tram |
1278B - A and B | 1353D - Constructing the Array |
1269C - Long Beautiful Integer | 1076A - Minimizing the String |
913C - Party Lemonade | 1313A - Fast Food Restaurant |
681A - A Good Contest | 1585F - Non-equal Neighbours |
747A - Display Size | 285A - Slightly Decreasing Permutations |